﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QLNH.MyDialogs
{
    public partial class CatalogDLG : Form
    {
        private bool _validText = true;
        private bool _edit = false;
        public bool Edit
        {
            get { return _edit; }
            set { _edit = value; }
        }

        public CatalogDLG()
        {
            InitializeComponent();
        }

        private void AddCatalogDLG_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = !_validText;
        }

        private void bt_ok_Click(object sender, EventArgs e)
        {
            if (this.tb_catalogName.Text.Trim().Equals(""))
            {
                _validText = false;
                this.lb_warning.Visible = true;
            }
            else
            {
                _validText = true;
            }
        }

        private void bt_cancel_Click(object sender, EventArgs e)
        {
            _validText = true;
        }

        private void tb_catalogName_TextChanged(object sender, EventArgs e)
        {
            if (_edit == true && this.bt_ok.Enabled == false)
                this.bt_ok.Enabled = true;

            if (this.lb_warning.Visible == true)
                this.lb_warning.Visible = false;
        }

        private void AddCatalogDLG_Load(object sender, EventArgs e)
        {
            if (this.lb_warning.Visible == true)
                this.lb_warning.Visible = false;

            if (_edit == true)
                this.bt_ok.Enabled = false;
            else
                this.bt_ok.Enabled = true;
        }
    }
}
